package ar.edu.itba.it.pdc;
import org.junit.Assert;
import org.junit.Test;

import ar.edu.itba.it.pdc.httpParser.HttpParser;
import ar.edu.itba.it.pdc.httpParser.HttpRequestParser;
import ar.edu.itba.it.pdc.httpParser.HttpResponseParser;
import ar.edu.itba.it.pdc.httpParser.ImputCharGetterImplTesting;
import ar.edu.itba.it.pdc.httpParser.Lexer;
import ar.edu.itba.it.pdc.httpParser.exceptions.HttpBadRequestException;
import ar.edu.itba.it.pdc.httpParser.exceptions.HttpMethodNotSuportedException;
import ar.edu.itba.it.pdc.httpParser.exceptions.HttpVersionNotSuportedException;
import ar.edu.itba.it.pdc.nio.Connection.ConectionType;


public class ParserTesting {
	
	@Test
	public void responseTest() throws HttpMethodNotSuportedException, HttpBadRequestException, HttpVersionNotSuportedException{
		Lexer lex = new Lexer(new ImputCharGetterImplTesting("HTTP/1.1 200 OK\nEncoding:UTF-8\n\n"),ConectionType.RESPONSE);
		HttpParser httpParser = new HttpResponseParser(lex, null);
		if(httpParser.parse()){
			 httpParser = new HttpResponseParser(lex, null);
		}
	}
	
	@Test
	public void requestTest() throws HttpMethodNotSuportedException, HttpBadRequestException, HttpVersionNotSuportedException{
		Lexer lex = new Lexer(new ImputCharGetterImplTesting("GET / HTTP/1.1\nHost:www.google.com.ar\n\n"),ConectionType.REQUEST);
		HttpParser httpParser = new HttpRequestParser(lex);
		if(httpParser.parse()){
			 httpParser = new HttpRequestParser(lex);
		}
	}
	
	@Test
	public void multilineHeaderRequestTest() throws HttpMethodNotSuportedException, HttpBadRequestException, HttpVersionNotSuportedException {
		Lexer lex = new Lexer(new ImputCharGetterImplTesting("GET / HTTP/1.1\nHost:www.google.com.ar\nTest:valor del header\n continuacion del valor del header\n\n"), ConectionType.REQUEST);
		HttpParser httpParser = new HttpRequestParser(lex);
		if(httpParser.parse()){
			Assert.assertTrue(httpParser.getModel().getHeaderValue("Host").equals("www.google.com.ar"));
			Assert.assertTrue(httpParser.getModel().getHeaderValue("Test").equals("valor del header continuacion del valor del header"));
			 httpParser = new HttpRequestParser(lex);
		}	
	}
	
}
